package org.doc.noliferadio.stuff;

import java.awt.Graphics;
import javax.swing.JLabel;

public class MarqueeLabel extends JLabel {

    private int MARQUEE_SPEED_DIV = 30;
    private int REPAINT_WITHIN_MS = 5;
    TextMode MODE;

    public MarqueeLabel() {
        MODE = TextMode.STATIC;
    }

    @Override
    protected void paintComponent(Graphics g) {
        if (MODE != TextMode.STATIC) {
            g.translate(-((int) ((System.currentTimeMillis() / MARQUEE_SPEED_DIV) % (getWidth() * 2)) - getWidth()), 0);
            super.paintComponent(g);
            repaint(getRepaintWithinMS());
        } else {
            super.paintComponent(g);
        }
    }

    public int getSpeed() {
        return MARQUEE_SPEED_DIV;
    }

    public void setSpeed(int MARQUEE_SPEED_DIV) {
        this.MARQUEE_SPEED_DIV = MARQUEE_SPEED_DIV;
    }

    public int getRepaintWithinMS() {
        return REPAINT_WITHIN_MS;
    }

    public void setRepaintWithinMS(int REPAINT_WITHIN_MS) {
        this.REPAINT_WITHIN_MS = REPAINT_WITHIN_MS;
    }

    public void setMode(TextMode mode) {
        MODE = mode;
    }

    public TextMode getMode() {
        return MODE;
    }
}
